// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Collections.Generic;

namespace SnapObjects.Data
{
    internal class NoGenericDataModelBinder : DataModelBinder<object>, IDataModelBinder
    {
        protected new IModelFactory _factory;

        public NoGenericDataModelBinder(DataModelBinding binding) : base(binding)
        {
        }

        public NoGenericDataModelBinder(
            Type modelType, IList<DbColumnInfo> columnSchema, ITypeMapper typeMapper)
            : base(ModelFactoryFactory.Create(modelType), columnSchema, typeMapper)
        {
        }

        IModelFactory IDataModelBinder.ModelFactory => _factory;

        protected override void SetValue(object model, int index, object value)
        {
            _accessor.SetValue(model, index, value);
        }

        protected override void SetValue(object model, string name, object value)
        {
            _accessor.SetValue(model, name, value);
        }
    }
}
